package com.wrater.zero.common.base.entity;

import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.wrater.zero.common.base.vo.BaseForm;
import lombok.Data;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

@Data
public abstract class BaseEntity<T extends BaseEntity, E extends BaseForm> extends BaseModelEntity {


    /**
     * 创建时间
     */
//    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
//    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
//    @JsonInclude(JsonInclude.Include.NON_NULL)
//    @TableField(fill = FieldFill.INSERT)
//    private LocalDateTime createTime;

    /**
     * 创建人
     */
//    private String createUser;

    /**
     * 修改时间
     */
//    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
//    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
//    @JsonInclude(JsonInclude.Include.NON_NULL)
//    @TableField(fill = FieldFill.UPDATE)
//    private LocalDateTime updateTime;

    /**
     * 修改人
     */
//    private String updateUser;


    /**
     * 返回实体类对应vo
     * @return
     */
    public abstract E buildVo();

    /**
     * 获取uuid
     * @return uuid
     */
    public static final String getUUID() {
        return UUID.randomUUID().toString().replaceAll("-", "");
    }


    /**
     * 重写方法
     * @return
     */
    public T selectById(){
        return (T) super.selectById();
    }

    public T selectById(Serializable id) {
        return (T) super.selectById(id);
    }

    public List selectAll(){
        List<T> list = new ArrayList<>();
        List<BaseModelEntity> lists = super.selectAll();
        for (BaseModelEntity base:lists) {
            list.add((T)base);
        }
        return  list;
    }

    public List selectAllVo(){
        List<BaseForm> list = new ArrayList<>();
        List<BaseModelEntity> lists = super.selectAll();
        for (BaseModelEntity base:lists) {
            list.add(((T)base).buildVo());
        }
        return  list;
    }

    public T selectOne(Wrapper<BaseModelEntity> queryWrapper) {
        return (T) super.selectOne(queryWrapper);
    }


}
